import { getList } from '@/api/freightManage'
import { ref } from 'vue';
import { Ifreight } from '@/types/data.d'
import dialogVue from '@/views/freightManage/components/dialog.vue';
export default function freightManageFn() {
  let listArr = ref<Ifreight | undefined>()
  /* 获取列表 */
  const getListFn = async (): Promise<void> => {
    const res = await getList()
    listArr.value = res.data.data
    console.log(listArr.value);
  }
  getListFn()


  let typeBtn = ref<string | undefined>()  // 判断编辑or新增
  let dialogTableVisible = ref<boolean>(false) // 显示弹窗
  const show = (val: string): void => { // 打开弹窗  判断编辑or 新增
    dialogTableVisible.value = true
    typeBtn.value = val
  }
  const close = (): void => { // 关闭弹窗
    dialogTableVisible.value = false
  }


  // 格式化前三列数据
  // 模板类型
  const formatterTemplateType = (row: any, column: any, cellValue: any, index: any) => {
    if (cellValue == 1) {
      return '同城寄'
    } else if (cellValue == 2) {
      return '省内寄'
    } else if (cellValue == 3) {
      return '经济区互寄'
    } else if (cellValue == 4) {
      return '跨省'
    }
  }
  // 运送类型
  const formatterTransportType = (row: any, column: any, cellValue: any, index: any) => {
    if (cellValue === 1) {
      return '普快'
    }
  }
  // 关联城市
  const formatterAssociatedCityList = (row: any, column: any, cellValue: any, index: any) => {
    if (cellValue == '1') {
      return '全国'
    } else if (cellValue == '2') {
      return '京津冀'
    } else if (cellValue == '3') {
      return '江浙沪'
    } else if (cellValue == '4') {
      return '川渝'
    } else if (cellValue == '5') {
      return '黑吉辽'
    }
  }




  // 表格头部的颜色
  function tableHeaderColor({ row, column, rowIndex, columnIndex }: never) {
    // console.log(rowIndex);
    if (rowIndex === 0) {
      return { 'background-color': '#f8faff', 'height': '48px' };
    }
  }

  return { typeBtn, close, dialogTableVisible, show, dialogVue, formatterAssociatedCityList, formatterTransportType, formatterTemplateType, listArr, tableHeaderColor }
}